package tsj.ai.alibaba.data.analysis.service.llm;

import org.springframework.ai.chat.model.ChatResponse;
import reactor.core.publisher.Flux;

import java.util.Optional;

/**
 * @author taoshujian
 * @version 1.0
 * @since 2025-11-14 11:35:38
 */
public interface LlmService {
    String call(String system, String user);

    String callSystem(String system);

    String callUser(String user);

    @Deprecated
    default String blockToString(Flux<ChatResponse> responseFlux) {
        return toStringFlux(responseFlux).collect(StringBuilder::new, StringBuilder::append)
                .map(StringBuilder::toString)
                .block();
    }

    default Flux<String> toStringFlux(Flux<ChatResponse> responseFlux) {
        return responseFlux.map(r -> r.getResult().getOutput()).map(r -> Optional.ofNullable(r.getText()).orElse(""));
    }
}
